// 贪心+排序；时间复杂度O(nlogn)；空间复杂度O(logn)

class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        sort(people.begin(), people.end());
        int left = 0, right = people.size() - 1;
        int ret = 0;
        while (left <= right) {
            if (people[left] + people[right] <= limit) {
                left++;
            }
            right--;
            ret++;
        }
        return ret;
    }
};